// ==UserScript==
// @name         bilibili_push
// @namespace    http://home.lan/
// @version      0.9
// @description  b站 push
// @author       you
// @match        https://www.bilibili.com/video/*
// @match        https://www.bilibili.com/list/*
// @match        https://www.bilibili.com/bangumi/*
// @match        https://m.bilibili.com/video/*
// @connect      *.tv.lan*
// @connect      *.server.lan*
// @connect      1.tv.lan
// @connect      172.21.18.209

// @grant        GM.xmlHttpRequest
// @grant        unsafeWindow
// @run-at       document-end

// @require      https://cdn.bootcss.com/jquery/3.4.1/jquery.min.js
// ==/UserScript==

/////////// https://greasyfork.org/zh-CN/scripts/439625-%E5%B1%8F%E8%94%BDb%E7%AB%99-bilibili-%E6%92%AD%E6%94%BE%E9%A1%B5%E9%9D%A2%E4%B8%AD%E5%8F%B3%E4%BE%A7%E7%9B%B8%E5%85%B3%E8%A7%86%E9%A2%91%E6%8E%A8%E8%8D%90%E4%B8%8E%E7%9B%B4%E6%92%AD%E5%B9%BF%E5%91%8A
(function () {
    'use strict';


    // //视频页面. 获取BVXXX  组成一个播放列表


    // // 手动,   生成 json.

    // // 为什么 console里可以读取, 而脚本里不行呢?? 权限问题!
    // console.log("----");
    // // console.log(unsafeWindow);
    // // console.log(window.__INITIAL_STATE__);
    // // console.log(window._sharedData);
    // console.log("----");

    const FROM_PUSHME = "from_pushme/from_bili/";
    const DEFAULT_PIC = "https://server.lan/file/test.png";
    let getTargetBoxUrlDebug = () => {
        return "http://localhost:9966/api/tvboxpush";
    }

    let getTargetBoxUrl = () => {
        // return getTargetBoxUrlDebug();
        // return "http://tv1.server.lan:9966/api/tvboxpush";
        return "http://v3.tv.server.lan:19999/api/tvboxpush";
    }



    // let window = unsafeWindow;

    // let result = {};
    // result.aid = ____data____.videoData.aid;
    // result.bvid = ____data____.videoData.bvid;
    // result.cid = ____data____.videoData.cid;
    // result.owner = owner.name; //up主 导演等
    // result.title = title;
    // result.pic = pic;
    // result.vod = [{title,aid,cid,pic?},{}];

    const gen__getVods = (key, ____data____, func_sections, func_section, func_episodes, func_getvod, fun_genNum) => {
        // // ugc_season.sections[i]episodes[j]
        let vod = [];
        let logCount = 0;
        let log = (s) => {
            logCount++;
            if (logCount > 15) {
                return;
            }
            console.log(s);
        }
        console.log(`====== ${key} ===========`)
        try {
            let sections = func_sections(____data____);// ->sections
            if (!sections) {
                return vod;
            }
            let n0 = 1;
            for (let i in sections) {//section
                let section = sections[i];

                if (func_section) {
                    section = func_section(section);
                }

                if (!section) {
                    continue
                }

                log(`${key}:: section: ${i}`);
                let n1 = 1;
                for (let j in section) {//->episodes
                    let episodes = func_episodes(section[j]);
                    if (!episodes) {
                        continue
                    }
                    let n2 = 1;
                    log(`${key}:: episodes: ${i}-${j}=${episodes.length}`);
                    for (let k in episodes) {//episode=video
                        let episode = episodes[k];
                        let data = func_getvod(episode);
                        if (data) {
                            log(`${key}::` + fun_genNum(n0, n1, n2));// episode: ${i}-${j}-${k}`);
                            data.title = fun_genNum(n0, n1, n2) + ` ${data.title}`; // 加上编号
                            vod.push(data);
                            n2++;
                        }

                    }
                    n1++;
                }
                n0++;
            }
        } catch (e) {
            console.log(e);
        }
        return vod;
    }

    const gen_new_result = (state) => {
        let result = {};
        result.aid = state.aid;
        let data = state.videoData;
        if (data) {
            if (data.aid && !result.aid) {
                result.aid = data.aid;
            }
            result.bvid = data.bvid;
            result.cid = data.cid;
            result.pic = data.pic;
            // result.year = data.ctime;
            try {
                let x = new Date(data.ctime * 1000)
                let y = x.getFullYear();
                let m = x.getMonth();
                if (y > 2000) {
                    result.year = `${y}.${m}`;
                }
            } catch (e) {

            }


            result.owner = data.owner ? data.owner.name : ""
            result.title = data.ugc_season ? data.ugc_season.title : null;
            if (!result.title) {
                result.title = data.title ? data.title : "";
            }
            let views = "";
            if (data.stat) {
                let v = null;
                try {
                    views = data.stat.view;
                    if (views > 10000) {
                        v = views / 10000;
                        if (v > 10000) {
                            v = "🔥" + parseInt(v / 10000) + "亿"
                        } else {
                            v = "🔥" + parseInt(v) + "w"
                        }
                    } else {
                        v = "🔥" + views;
                    }
                } catch (e) {

                }
                if (v) {
                    result.remarks = v;
                } else {
                    result.remarks = "";
                }
            }
            // ?data.stat.view: "";

        }
        return result;
    }
    // gen_new_result(__INITIAL_STATE__);

    const get_longestArray = (...arrs) => {
        let arr = [];
        for (let i in arrs) {
            if (arrs[i].length > arr.length) {
                arr = arrs[i];
            }
            console.log(`array i=${i}, length=${arrs[i].length}`);
        }
        return arr;
    }

    let get_details_episode = () => {
        let ____data____ = unsafeWindow.__INITIAL_STATE__;

        if (!____data____.videoData) {
            console.log("____data____.videoData == null")
            return false;
        }

        let result = gen_new_result(____data____);

        let default_getvod = (episode, aid) => {
            let data = {};
            if (!(episode && episode.cid)) {
                return data;
            }
            data.aid = episode.aid ? episode.aid : aid;
            data.cid = episode.cid;
            data.title = episode.title;
            return data;
        }

        let default_fun_genNum1 = (n0, n1, n2) => {
            return `(${n2})`;
        }

        let default_fun_genNum2 = (n0, n1, n2) => {
            return `(${n1}-${n2})`;
        }

        let default_fun_genNum3 = (n0, n1, n2) => {
            return `(${n0}-${n1}-${n2})`;
        }

        let func_sections, func_section, func_episodes, getvod, fun_genNum;
        /////////////////////
        // try: 1
        func_sections = (obj) => {
            if (obj)
                return obj.sections
            return null
        }

        func_section = (section) => {
            if (section) {
                return section;
            }
            return null;
        };

        func_episodes = (section) => {
            if (section)
                return section;
            return null;
            // return section.episodes
        }

        getvod = (episode, aid) => {
            let data = {};
            if (!(episode && episode.cid)) {
                return data;
            }
            data.aid = episode.aid ? episode.aid : aid;
            data.cid = episode.cid;
            data.title = episode.title;
            if (episode.arc) {
                data.pic = episode.arc.pic;
                // console.log(episode.arc.pic);
            }
            return data;
        }

        fun_genNum = default_fun_genNum3;

        let vod1 = gen__getVods("try1", ____data____, func_sections, func_section, func_episodes, getvod, fun_genNum);

        /////////////////////
        // try: 2
        func_sections = (obj) => {
            // 只有两层 ,强行 加一层
            if (obj)
                return [obj];
            return null;
        }

        func_section = (section) => {
            if (section) {
                return section.availableVideoList;
            }
            return null;
        };

        func_episodes = (section) => {
            console.log("section", section);
            if (section)
                return section.list;
            return null;
        }

        getvod = default_getvod;
        fun_genNum = default_fun_genNum2;
        let vod2 = gen__getVods("try2", ____data____, func_sections, func_section, func_episodes, getvod, fun_genNum);

        /////////////////////
        // try: 3
        func_sections = (obj) => {
            // 只有两层 ,强行 加一层
            if (obj)
                try {
                    let sections = obj.videoData.ugc_season.sections;
                    console.log("sections", sections);
                    return [sections];
                } catch {

                }

            return null;
        }

        func_section = (section) => {
            console.log("section", section);
            if (section) {
                return section;
            }
            return null;
        };

        func_episodes = (section) => {
            console.log("func_episodes", section);
            if (section)
                return section.episodes;
            return null;
        }

        getvod = (episode, aid) => {
            let data = {};
            if (!(episode && episode.cid)) {
                return data;
            }
            data.aid = episode.aid ? episode.aid : aid;
            data.cid = episode.cid;
            data.title = episode.title;
            if (episode.arc) {
                data.pic = episode.arc.pic;
                // console.log(episode.arc.pic);
            }
            return data;
        };
        fun_genNum = default_fun_genNum2;
        let vod3 = gen__getVods("try3", ____data____, func_sections, func_section, func_episodes, getvod, fun_genNum);

        /////////////////////////
        let vods = [];
        vods.push(vod1);
        console.log("vod1");
        console.log(vod1);

        // vods.push(vod2); // 这个 包含推荐视频!!!
        console.log("vod2");
        console.log(vod2);

        vods.push(vod3);
        console.log("vod3");
        console.log(vod3);
        // console.log(vods);
        /////////////////////////
        let vod = get_longestArray(...vods)

        // if (vod1.length > vod2.length) {
        //     vod = vod1;
        // } else {
        //     vod = vod2;
        // }

        if (vod.length == 0) {
            console.log("____data____.videoData|availableVideoList :: len(vod.length)==0")
            return false;
        }

        result.vod = vod;
        console.log("____data____.videoData == yes")
        return result;

        // // 注意 json  不需要 引号包起来 
        //      '{.....}'  <- not ok
        //      {....} <- ok

    }

    let get_details_bvid = () => {
        let ____data____ = unsafeWindow.__INITIAL_STATE__;
        if (!____data____.videoData.pages) {
            console.log("____data____.videoData.pages == null")
            return false;
        }

        let result = gen_new_result(____data____);

        let vod = [];
        try {
            //// let pages = ____data____.videoData.pages;// 播放列表在这里面
            for (let i in ____data____.videoData.pages) {
                let page = ____data____.videoData.pages[i];
                let episode = {};
                episode.aid = page.aid ? page.aid : result.aid;
                episode.title = page.part;
                episode.cid = page.cid;
                episode.pic = "";
                vod.push(episode);
            }
        } catch (e) {
            console.log(e);
        }

        
        // www.bilibili.com/list/
        if(____data____.resourceList){
            let vod2 = [];
            try {
                //// let pages = ____data____.videoData.pages;// 播放列表在这里面
                let n=1;
                for (let i in ____data____.resourceList) {
                    // 这个 获取不到完整的! , 需要滚动 播放列表到底部才能 获取全部的视频!
                    let page = ____data____.resourceList[i];
                    if(!page)continue;
                    if(!page.id)continue;
                    let episode = {};
                    episode.aid = page.id;
                    episode.title = page.title?page.title:""+n;
                    episode.pic = page.cover;
                    if(page.pages){
                        for(let j in page.pages){
                            let page_j=page.pages[j];
                            let cid=page_j.id;
                            if(cid){
                                let title=page_j.title?page_j.title:""+n;
                                vod2.push({
                                    aid:episode.aid,
                                    cid:cid,
                                    title:title,
                                    pic:episode.pic,
                                });
                                n++;
                            }
                        }
                    }else{
                        episode.cid = page.cid;
                        vod2.push(episode);
                        n++;
                    }
                    
                }
            } catch (e) {
                console.log(e);
            }
            if(vod.length<vod2.length){
                vod=vod2;
            }
        }



        if (vod.length == 0) {
            console.log("____data____.sections :: len(vod.length)==0")
            return false;
        }
        result.vod = vod;
        console.log("____data____.sections == yes")
        console.log(vod);
        return result;
    }


    // let gen_form_urlencoded = (kv) => {
    //     // "Content-Type": "application/x-www-form-urlencoded"
    //     let data = [];
    //     for (const key in kv) {
    //         if (typeof kv[key] !== 'function') {
    //             // console.log(`${key}: ${kv[key]}`);
    //             data.push(encodeURIComponent(key) + "=" + encodeURIComponent(kv[key]));
    //         }
    //     }
    //     if (data.length <= 0) {
    //         return false;
    //     }
    //     data = data.join("&");
    //     return data;
    // }

    let http_post_json = (url, kv) => {
        let data = JSON.stringify(kv);
        if (data.length <= 10) {
            return false;
        }
        console.log("push_to_server")
        console.log(data);
        GM.xmlHttpRequest({
            method: "POST",
            url: url,
            data: data,
            headers: {
                "Content-Type": "application/json",
            },
            onload: function (res) {
                let x = res.responseText;
                console.log("[i] responce:" + x);
            },
            onerror: function (res) {
                let x = res.responseText;
                console.log("[err]:" + x);
            }
        })
        return true;
    }

    let get_result = () => {
        location.pathname
        const funcs = [get_details_episode, get_details_bvid];

        let result;
        let err;
        for (let i in funcs) {
            try {
                result = funcs[i]();
                if (result) {
                    break;
                }
            } catch (e) {
                err = e;
            }
        }
        if (result) return result;
        console.log(err);
        return null;
    }


    let push_result = (result, download_pic = true, show=false) => {
        if (!result) {
            return null;
        }
        let vod = result.vod;
        let url_list = [];
        let pic = result.pic;
        let title = result.title ? result.title : "";
        let aid = result.aid;
        for (let i = 0; i < vod.length; i++) {
            let episode = vod[i]; // aid, cid, title, pic, 

            if (episode.aid && episode.cid) {
                if (!aid) aid = episode.aid;
                let title1 = "";
                if (episode.title) {
                    title1 = episode.title.replaceAll("\$", " ") + "$";
                }
                // let url = title + "USE_HOMESOURCEBEAN_http://server.lan:9967/from_bilibili/" + episode.aid + "/" + episode.cid;
                let url = title1 + "/api/onlinevod/from_bili/" + episode.aid + "/" + episode.cid;
                url_list.push(url);
                if ((!pic) && episode.pic) {
                    pic = episode.pic;
                }
            }
        }


        // Year        string `gorm:"type:varchar(20)" json:"vod_year,omitempty"`
        // Remark      string `json:"vod_remarks,omitempty"`
        // Area        string `json:"vod_area,omitempty"`
        // Type        string `json:"type_name,omitempty"`
        // Actors      string `json:"vod_actor,omitempty"`
        // Director    string `json:"vod_director,omitempty"`
        // Description string `json:"vod_content,omitempty"`
        // // Plays          []Play `json:"list,omitempty"`

        // //
        // VodId    string `gorm:"-" json:"vod_id"` // == ID 或 SubId非空时 ==/others/SubId/ID
        // FolderId uint   `gorm:"index" json:"-"`
        // DetailId uint   `gorm:"index" json:"-"`
        // // Plays []OthersPlay `json:"-"`
        // Vod_play_url  string `gorm:"-" json:"vod_play_url,omitempty"`
        // Vod_play_from string `gorm:"-" json:"vod_play_from,omitempty"` // not null

        if (url_list.length > 0) {
            //const PIC="";
            let playlist = url_list.join("#");
            let kv = {};
            let vod = {};
            vod.vod_id = FROM_PUSHME + aid;// "bilibili_episode:" + title;
            vod.vod_director = result.owner;
            vod.vod_remarks = result.remarks ? result.remarks : "";
            vod.vod_year = result.year;
            vod.vod_actor = ""+result.aid;

            vod.vod_name = title;
            vod.vod_tag = "file";
            vod.vod_pic = pic ? pic : "";
            vod.vod_play_from = "bili";
            vod.vod_play_url = playlist;
            vod.vod_play_url_fetch = "/api/onlinevod/from_bili/" + aid;


            kv.do = "push_vod";
            kv.sourceKey = "bilibili_query_play";
            kv.prefix = "bilibili_" + aid;
            kv.download_pic = download_pic;
            kv.vod = vod;

            // HomeActivity 中 true==显示, false==不显示
            if(show){
                kv.show=true;
            }else{
                kv.show=false;
            }
            let actionUrl = getTargetBoxUrl();
            return http_post_json(actionUrl, kv);

        }

        return false;

    }

    let push_to_server = (show) => {
        // action do=push
        // url=name$url#
        let result = get_result();
        return push_result(result,true,show);
    }

    const get_page_url = () => {
        return location.href;
    }
    const get_page_path = () => {
        // // return location.href;
        // console.log(location.href, ",", location.pathname,",",!location.pathname);
        return location.pathname ? location.pathname : get_page_url();
    }


    function get_fallback() {

        // 解析失败之后 只推 bvid | aid
        console.log("push_fallback");
        const ____BILI_URL = "bilibili.com/video/";
        const get_title = () => {
            let title;
            try {
                title = document.querySelector("div.video-info-title > div > h1").innerText;
            } catch {
                title = document.title;
            }
            if (!title) {
                title = "no title found";
            }
            return title
        }


        const get_ids = () => {
            let ids = {};
            let url = get_page_url();
            let index = url.indexOf(____BILI_URL);
            if (index >= 0) {
                //    url.startsWith("https://www.bilibili.com/video/")
                //    if(url.startsWith("https://www.bilibili.com/video/")||url.startsWith("https://m.bilibili.com/video/")){
                //        https://www.bilibili.com/video/BV1Yt411B7kU/?p=9&spm_id_from=pageDriver
                //        https://m.bilibili.com/video/BV1Yt411B7kU?p=9&spm_id_from=pageDriver
                let bvid_or_aid = url.substring(____BILI_URL.length + index);
                index = bvid_or_aid.indexOf("?"); //  BV1Yt411B7kU/?args -> BV1Yt411B7kU/
                if (index > 0) bvid_or_aid = bvid_or_aid.substring(0, index);
                index = bvid_or_aid.indexOf("/"); //  BV1Yt411B7kU/ -> BV1Yt411B7kU/

                if (index > 0) bvid_or_aid = bvid_or_aid.substring(0, index);
                let someid = bvid_or_aid.toLowerCase();
                let bvid, aid;
                if (someid.startsWith("av")) {
                    aid = bvid_or_aid.substring(2);
                } else if (someid.startsWith("bv")) {
                    bvid = bvid_or_aid;//.substring(2);
                } else {
                    // aid = bvid_or_aid;
                }
                if (aid) {
                    ids.aid = aid;
                }
                if (bvid) {
                    ids.bvid = bvid;
                }
                if (bvid_or_aid) {
                    ids.bvid_or_aid = bvid_or_aid;
                }
            }
            return ids;
        }
        let ids = get_ids();
        let title = get_title();

        console.log(ids, title);

        if (!(ids.aid || ids.bvid)) {
            console.log(" >>>>>>>> ==============> push ERROR");
            return
        }

        if (!title) {
            title = "push:" + ids.bvid_or_aid;
        };

        // let vid = FROM_PUSHME + bvid_or_aid;

        let pic, pages;

        let vod = [{
            aid: ids.aid ? ids.aid : ids.bvid ? ids.bvid : ids.bvid_or_aid,
            // cid:
            title: title,
            pic: pic ? pic : DEFAULT_PIC,
        }];

        let result = {
            aid: vod[0].aid,
            // bvid:ids.bvid,
            // cid:
            // owner:
            title: vod[0].title,
            pic: vod[0].pic,
            vod: vod,
        }

        return result;
    }


    function push_fallback(show) {
        let result = get_fallback();
        push_result(result, false, show);
    }

    function push(show) {
        try {
            if (push_to_server(show)) {
                // 列表
                console.log("= push_to_server");
                return;
            };
        } catch (e) {
            console.log(e);
        }
        push_fallback(show);
    }



    let block = document.createElement("div");
    block.style.height = "25px";

    block.style.position = "absolute";
    block.style.zIndex = "9999";
    if (unsafeWindow.innerHeight < unsafeWindow.innerWidth) {
        const top="-42px"
        block.style.top = top;
        block.style.left = "0px";
        //block.style.padding = "10px";

        block.addEventListener("mouseenter", () => {
            block.style.top = "0px";
        });

        block.addEventListener("mouseleave", () => {
            block.style.top = top;
        });
    } else {
        block.style.top = "0px";
        block.style.left = "0px";
    }

    let mk_btn = (name, func) => {

        let btn = document.createElement("button");
        btn.innerText = name;
        btn.style.height = "25px";
        // //    b.classList.add("host");
        //     "weui-cell__control weui-btn weui-btn_default weui-vcode-btn".split(" ").forEach((c)=>{
        //             b.classList.add(c);
        //     });
        btn.addEventListener("click", func);
        return btn;
    }
    // btn.style.position = "absolute";
    // btn.style.top = "0px";
    // btn.style.left = "0px";
    // btn.style.padding = "10px";
    // btn.style.zIndex = "9999";
    // b.style.padding="10px";
    // b.style.padding="10px";
    // b.style.padding="10px";

    // background-color: #f9f9f9;
    // border: 1px solid #ddd;
    // margin: 15px;

    $(block).append(mk_btn("push", () => {
        if(is_bangumi()){
            push_bangumi();
            return;
        }

        setTimeout(() => {
            push();
        }, 0);
    }));

    // //push_to_server; 已经合并到 push按钮
    // $(block).append(mk_btn("push_to_server", () => {
    //     setTimeout(() => {
    //         push_to_server();
    //     }, 0);
    // }));

    //gen_episode
    $(block).append(mk_btn("gen_episode_data", () => {
        if(is_bangumi()){
            console.log(get_bangumi());
            return;
        }
        setTimeout(() => {
            let detail = get_result();
            // result.tostring();
            let __res__ = ""
            __res__ = "\n" + JSON.stringify(detail) + "\n";
            console.log(__res__)
            console.log(detail);
        }, 0);

        // save to
        /////////          xxxx.bili.others/episodes.bili/yyy.json

        // 注意 json 不需要 引号包起来
        //           '{.....}'
    }));
    {
        if (location.pathname.startsWith("/list/")){
            let span=document.createElement("span");
            const add=(content,color="white")=>{
                let s=document.createElement("span");
                s.textContent=content;
                if(color){
                    s.style.color=color;
                }
                s.style.background="grey";
                span.appendChild(s);
            }
            
            // span.textContent="www.bilibili.com/list/xxx 需要滚动播放列表到底部, 否则只能获取前20个视频";
            span.style.marginLeft="10px";
            span.style.padding="10px";
            span.style.background="grey";
            span.style.color="white";
            add("注意: ","red");
            add("需要滚动播放列表到底部, 否则只能获取前20个视频","blue");
            add("( www.bilibili.com/list/<xxx> ) ");

            $(block).append(span);
        }
    }

    {
        let btn=mk_btn("push ✅", () => {
            console.log("push ✅ : show=true", "HomeActivity 中 show==true==>显示, show==false==>不显示");
            if(is_bangumi()){
                push_bangumi(true);
                return;
            }

            setTimeout(() => {
                push(true);
            }, 0);
        });
        btn.style.display="block";
        $(block).append(btn);
    }

    $("body").append(block);
    console.log("###########yes#################");

    function is_bangumi(){
        if (location.pathname.startsWith("/bangumi/")){
            return true;
        }
        return false;
    }

    function get_bangumi(){
        const f=()=>{
            let left=document.querySelector("div.main-container div.player-left-components");
            let result=null;
            try{
                result=unsafeWindow.playurlSSRData.result;
            }catch(e){
                try{
                    result=playurlSSRData.result;
                }catch(e){
                    console.log("[E] can't find playurlSSRData.result");
                }
            }
 

            let title="";
            let pic=null;
            let seasonid="";
            let id="";

            left.querySelectorAll("a").forEach((a)=>{
                if(a.title&&a.title==a.textContent){
                    title=a.title;
                    console.log(`title=${title}`);
                }
            });

            let img=left.querySelectorAll("a   picture  img");
            try{
                pic=img[0].src;
                console.log(`pic=${pic}`);
            }catch(e){
            }

            seasonid=result.play_view_business_info.season_info.season_id;
            id="season_id_" + seasonid;

            let kv = {};
            let vod = {};
            
            vod.vod_id = FROM_PUSHME + id;// "bilibili_episode:" + title;
            vod.vod_director = "";
            vod.vod_remarks = "season";
            vod.vod_year = "";
            vod.vod_actor = ""+id;

            vod.vod_name = title;
            vod.vod_tag = "file";
            vod.vod_pic = pic ? pic : "";
            vod.vod_play_from = "bili";
            vod.vod_play_url = "";
            vod.vod_play_url_fetch = "/api/onlinevod/from_bili/" + id;

            kv.do = "push_vod";
            kv.sourceKey = "bilibili_query_play";
            kv.prefix = "bilibili_" + id;
            kv.download_pic = true;
            kv.vod = vod;

            kv.show=false;// HomeActivity 中 true==显示, false==不显示
            return kv;
        }
        return f();
    }

    function push_bangumi(show){
        let kv=get_bangumi();
        let actionUrl = getTargetBoxUrl();
        if(show){
            kv.show=true;
        }else{
            kv.show=false;
        }
        return http_post_json(actionUrl, kv);
    }

})();



/*


event: ("suspend"); //延迟下载
event: ("abort"); //客户端主动终止下载（不是因为错误引起）
event: ("loadstart"); //客户端开始请求数据
event: ("progress"); //客户端正在请求数据
event: ("suspend"); //延迟下载
event: ("abort"); //客户端主动终止下载（不是因为错误引起），
event: ("error"); //请求数据时遇到错误
event: ("stalled"); //网速失速
event: ("play"); //play()和autoplay开始播放时触发
event: ("pause"); //pause()触发
event: ("loadedmetadata"); //成功获取资源长度
event: ("loadeddata"); //
event: ("waiting"); //等待数据，并非错误
event: ("playing"); //开始回放
event: ("canplay"); //可以播放，但中途可能因为加载而暂停
event: ("canplaythrough"); //可以播放，歌曲全部加载完毕
event: ("seeking"); //寻找中
event: ("seeked"); //寻找完毕
event: ("timeupdate"); //播放时间改变
event: ("ended"); //播放结束
event: ("ratechange"); //播放速率改变
event: ("durationchange"); //资源长度改变
event: ("volumechange"); //音量改变
*/

